package com.qianlou.springai01chat.controller;


import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.ai.openai.OpenAiAudioTranscriptionModel;
import org.springframework.ai.openai.audio.transcription.AudioTranscriptionPrompt;
import org.springframework.ai.openai.audio.transcription.AudioTranscriptionResponse;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
@Slf4j
@RestController
public class VoiceTransferController {

    @Resource
    private OpenAiAudioTranscriptionModel openAiAudioTranscriptionModel;

    @RequestMapping("/ai/transcription")
    public String transcription(@RequestParam("file") MultipartFile file) {
        AudioTranscriptionPrompt transcriptionRequest = new AudioTranscriptionPrompt(file.getResource());
        AudioTranscriptionResponse response = openAiAudioTranscriptionModel.call(transcriptionRequest);
        log.info("transcription response: {}", response.getResult().getOutput());
        return response.getResult().getOutput();
    }

}
